﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DA
{
    public class HoaDon_DA
    {
        QLKhachSanDataContext HDDA;

        public List<HoaDon> LayDSHoaDon()
        {
            try
            {
                HDDA = new QLKhachSanDataContext();
                return HDDA.HoaDons.ToList();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                HDDA.Dispose();
            }
        }
        public bool ThemHoaDon(HoaDon K)
        {
            try
            {
                HDDA = new QLKhachSanDataContext();
                HoaDon s = new HoaDon();
                s.MaHD = K.MaHD;
                s.MaKH = K.MaKH;
                s.MaNhatKy = K.MaNhatKy;
                s.NguoiLap = K.NguoiLap;
                s.NgayLap = K.NgayLap;
                s.SoNgayO = K.SoNgayO;
                s.GiaPhong = K.GiaPhong;
                s.TongTienDV = K.TongTienDV;
                s.PhuThuKhac = K.PhuThuKhac;
                s.ThanhTien = K.ThanhTien;
                HDDA.HoaDons.InsertOnSubmit(s);
                HDDA.SubmitChanges();
                return true;

            }
            catch
            {
                return false;
            }
            finally
            {
                HDDA.Dispose();
            }
        }
        public bool SuaHoaDon(HoaDon K)
        {
            try
            {
                HDDA = new QLKhachSanDataContext();
                HoaDon s = HDDA.HoaDons.Where(p => p.MaHD == K.MaHD).FirstOrDefault();
                s.MaKH = K.MaKH;
                s.MaNhatKy = K.MaNhatKy;
                s.NguoiLap = K.NguoiLap;
                s.NgayLap = K.NgayLap;
                s.SoNgayO = K.SoNgayO;
                s.GiaPhong = K.GiaPhong;
                s.TongTienDV = K.TongTienDV;
                s.PhuThuKhac = K.PhuThuKhac;
                s.ThanhTien = K.ThanhTien;
                HDDA.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
            finally
            {
                HDDA.Dispose();
            }
        }
        public bool XoaHoaDon(string ma)
        {
            try
            {
                HDDA = new QLKhachSanDataContext();
                HoaDon s = HDDA.HoaDons.Where(p => p.MaHD == ma).FirstOrDefault();
                HDDA.HoaDons.DeleteOnSubmit(s);
                HDDA.SubmitChanges();
                return true;

            }
            catch
            {
                return false;
            }
            finally
            {
                HDDA.Dispose();
            }
        }
     
    }
}
